//
//  RAPBadgeTabBarItem.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 1/3/16.
//  Copyright © 2016 RendezvousAuParadis. All rights reserved.
//

import UIKit

//_target

class RAPBadgeTabBarItem: UITabBarItem {
    override var badgeValue: String? {
        didSet {
            let target = valueForKey("_target") as! RAPMainInterfaceTabBarController
            
            for chd in target.tabBar.subviews {
                if chd.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                    for sChd in chd.subviews {
                        if sChd.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                            for ssChd in sChd.subviews {
                                if ssChd.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                    RAPLog("更改badge value 样式")
                                    ssChd.setValue(UIImage(named: "main_badge"), forKey: "_image")
                                }
                            }
                        }
                    }
                }

            }
            
            
//            var outCount: UInt32 = 0
//            let ivar = class_copyIvarList(UITabBarItem.self, &outCount)
//            RAPLog(outCount)
//            for idx in 0..<outCount {
//                let x = ivar[Int(idx)]
//                let nameStr = ivar_getName(x)
//                RAPLog(NSString(CString: nameStr, encoding: NSUTF8StringEncoding))
//            }
        }
    }
}
